package com.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class NPECatchAspect {

    @Pointcut("@within(com.aop.NPECatch) || @annotation(com.aop.NPECatch)")
    public void npeCatchPointcut() {}

    @AfterThrowing(pointcut = "npeCatchPointcut()", throwing = "e")
    public void handleNPE(JoinPoint joinPoint, NullPointerException e) {
        System.out.println("Exception caught in " + joinPoint.getSignature() + ": " + e.getMessage());
    }
}
